function [F1, F11, F2, F22, F3, F4] = GAD_Etom_Cross_Day_PV_DeltaT(XDay_PV_Summary)
%% get cross-day PV vs deltaT for G17

T1(:,1) = (extractfield(XDay_PV_Summary.G2_F4_17, 'Date1'))';
T1(:,2) = (extractfield(XDay_PV_Summary.G2_F4_17, 'Date2'))';
T1 = datetime(T1,'InputFormat','yyyy-MM-dd');

for n = 1:size(T1,1)
    deltaT1(n,1) = daysact(T1(n,1),T1(n,2));
end

PV1 (:,1) = extractfield(XDay_PV_Summary.G2_F4_17, 'Memory_Index');

%% get cross-day PV vs deltaT for G18

T2(:,1) = (extractfield(XDay_PV_Summary.G2_F4_18, 'Date1'))';
T2(:,2) = (extractfield(XDay_PV_Summary.G2_F4_18, 'Date2'))';
T2 = datetime(T2,'InputFormat','yyyy-MM-dd');

for n = 1:size(T2,1)
    deltaT2(n,1) = daysact(T2(n,1),T2(n,2));
end

PV2 (:,1) = extractfield(XDay_PV_Summary.G2_F4_18, 'Memory_Index');

%% get cross-day PV vs deltaT for G21

T3(:,1) = (extractfield(XDay_PV_Summary.G2_F52_21, 'Date1'))';
T3(:,2) = (extractfield(XDay_PV_Summary.G2_F52_21, 'Date2'))';
T3 = datetime(T3,'InputFormat','yyyy-MM-dd');

for n = 1:size(T3,1)
    deltaT3(n,1) = daysact(T3(n,1),T3(n,2));
end

PV3 (:,1) = extractfield(XDay_PV_Summary.G2_F52_21, 'Memory_Index');

%% get cross-day PV vs deltaT for G28

T4(:,1) = (extractfield(XDay_PV_Summary.G2_F52_28, 'Date1'))';
T4(:,2) = (extractfield(XDay_PV_Summary.G2_F52_28, 'Date2'))';
T4 = datetime(T4,'InputFormat','yyyy-MM-dd');

for n = 1:size(T4,1)
    deltaT4(n,1) = daysact(T4(n,1),T4(n,2));
end

PV4 (:,1) = extractfield(XDay_PV_Summary.G2_F52_28, 'Memory_Index');

%% get cross-day PV vs deltaT for G31

T5(:,1) = (extractfield(XDay_PV_Summary.G2_F52_31, 'Date1'))';
T5(:,2) = (extractfield(XDay_PV_Summary.G2_F52_31, 'Date2'))';
T5 = datetime(T5,'InputFormat','yyyy-MM-dd');

for n = 1:size(T5,1)
    deltaT5(n,1) = daysact(T5(n,1),T5(n,2));
end

PV5 (:,1) = extractfield(XDay_PV_Summary.G2_F52_31, 'Memory_Index');

%% get cross-day PV vs deltaT for G34

T6(:,1) = (extractfield(XDay_PV_Summary.G2_F52_34, 'Date1'))';
T6(:,2) = (extractfield(XDay_PV_Summary.G2_F52_34, 'Date2'))';
T6 = datetime(T6,'InputFormat','yyyy-MM-dd');

for n = 1:size(T6,1)
    deltaT6(n,1) = daysact(T6(n,1),T6(n,2));
end

PV6 (:,1) = extractfield(XDay_PV_Summary.G2_F52_34, 'Memory_Index');

%% get cross-day PV vs deltaT for G45

T7(:,1) = (extractfield(XDay_PV_Summary.G2_F52_45, 'Date1'))';
T7(:,2) = (extractfield(XDay_PV_Summary.G2_F52_45, 'Date2'))';
T7 = datetime(T7,'InputFormat','yyyy-MM-dd');

for n = 1:size(T7,1)
    deltaT7(n,1) = daysact(T7(n,1),T7(n,2));
end

PV7 (:,1) = extractfield(XDay_PV_Summary.G2_F52_45, 'Memory_Index');

%% get cross-day PV vs deltaT for G53

T8(:,1) = (extractfield(XDay_PV_Summary.G2_F52_53, 'Date1'))';
T8(:,2) = (extractfield(XDay_PV_Summary.G2_F52_53, 'Date2'))';
T8 = datetime(T8,'InputFormat','yyyy-MM-dd');

for n = 1:size(T8,1)
    deltaT8(n,1) = daysact(T8(n,1),T8(n,2));
end

PV8 (:,1) = extractfield(XDay_PV_Summary.G2_F52_53, 'Memory_Index');

%% get cross-day PV vs deltaT for G36

T9(:,1) = (extractfield(XDay_PV_Summary.G2_F62_36, 'Date1'))';
T9(:,2) = (extractfield(XDay_PV_Summary.G2_F62_36, 'Date2'))';
T9 = datetime(T9,'InputFormat','yyyy-MM-dd');

for n = 1:size(T9,1)
    deltaT9(n,1) = daysact(T9(n,1),T9(n,2));
end

PV9 (:,1) = extractfield(XDay_PV_Summary.G2_F62_36, 'Memory_Index');

%% get cross-day PV vs deltaT for G42

T10(:,1) = (extractfield(XDay_PV_Summary.G2_F62_42, 'Date1'))';
T10(:,2) = (extractfield(XDay_PV_Summary.G2_F62_42, 'Date2'))';
T10 = datetime(T10,'InputFormat','yyyy-MM-dd');

for n = 1:size(T10,1)
    deltaT10(n,1) = daysact(T10(n,1),T10(n,2));
end

PV10 (:,1) = extractfield(XDay_PV_Summary.G2_F62_42, 'Memory_Index');

%% linear regression

T_WT = cat(1,deltaT2,deltaT4,deltaT5,deltaT6,deltaT10);
PV_WT = cat(1,PV2,PV4,PV5,PV6,PV10);

T_MUT = cat(1,deltaT1,deltaT3,deltaT7,deltaT8,deltaT9);
PV_MUT = cat(1,PV1,PV3,PV7,PV8,PV9);

figure
subplot(1,2,1)
F1 = fit(T_WT,PV_WT,'poly1');
plot(F1,T_WT,PV_WT,'ob');
xlabel('deltaT (days)')
ylabel('PV memory index')
title('\alpha5-i-WT cross-day PV vs deltaT')
ylim([-0.2,0.6])
xlim([0,70])
legend('off')
% set(gca,'visible','off');

subplot(1,2,2)
F2 = fit(T_MUT,PV_MUT,'poly1');
plot(F2,T_MUT,PV_MUT,'ob');
xlabel('deltaT (days)')
ylabel('PV memory index')
title('\alpha5-i-KO cross-day PV vs deltaT')
ylim([-0.2,0.6])
xlim([0,90])
legend('off')
% set(gca,'visible','off');

F11 = fitlm(T_WT,PV_WT);
F22 = fitlm(T_MUT,PV_MUT);

%% Alternatively, exponential regression

figure
subplot(1,2,1)
F3 = fit(T_WT,PV_WT,'exp1');
plot(F3,T_WT,PV_WT,'^b');
xlabel('deltaT (days)')
ylabel('PV memory index')
title('\alpha5-i-WT cross-day PV vs deltaT')
ylim([-0.2,0.6])
xlim([0,70])
legend('off')


subplot(1,2,2)
F4 = fit(T_MUT,PV_MUT,'exp1');
plot(F4,T_MUT,PV_MUT,'^b');
xlabel('deltaT (days)')
ylabel('PV memory index')
title('\alpha5-i-KO cross-day PV vs deltaT')
ylim([-0.2,0.6])
xlim([0,90])
legend('off')


%% Plot for GAD paper graph (function obtained from fit already)
% % figure 
% % subplot(1,2,1)
% % plot(T_WT,PV_WT,'ob');
% % hold on
% % fplot(@(x) 0.2021*exp(-0.01806*x), 'r', 'LineWidth', 4)
% % xlabel('deltaT (days)')
% % ylabel('PV memory index')
% % title('\alpha5-i-WT cross-day PV vs deltaT')
% % ylim([-0.2,0.6])
% % xlim([0,90])
% % legend('off')
% % set(gca,'visible','off');
% % hold off
% % 
% % subplot(1,2,2)
% % plot(T_MUT,PV_MUT,'^b');
% % hold on
% % fplot(@(x) 0.2248*exp(-0.02941*x), 'r', 'LineWidth', 4)
% % xlabel('deltaT (days)')
% % ylabel('PV memory index')
% % title('\alpha5-i-KO cross-day PV vs deltaT')
% % ylim([-0.2,0.6])
% % xlim([0,90])
% % legend('off')
% % set(gca,'visible','off');
% % hold off

end